﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using BUS;
using Public;

namespace QuanLyKhoHangVatTu
{
    public partial class ChiTietNhapKho : DevExpress.XtraEditors.XtraForm
    {
        NhapKho_BUS nk_bus = new NhapKho_BUS();
        NhapKho_PB nk_pn = new NhapKho_PB();
        Flag_PB flag = new Flag_PB();

        public ChiTietNhapKho()
        {
            InitializeComponent();
        }

        private void xtraTabPage3_Paint(object sender, PaintEventArgs e)
        {

        }

        private void xtraTabPage1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void ChiTietNhapKho_Load(object sender, EventArgs e)
        {
            Flag_PB.Flag = 5;
            gridNhapKho.DataSource = nk_bus.LayDSPhieuNhap();
        }

        private void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            string ma = NhapKho_PB.MaPhieuNhap = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MAPHIEUNHAP").ToString();
            gridChiTietNhap.DataSource = nk_bus.TimMaPhieuNhap(ma);
            NhapKho_PB.MaPhieuNhap=gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MAPHIEUNHAP").ToString();
            NhapKho_PB.MaNCC = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MANCC").ToString();
            NhapKho_PB.TenNCC = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TENNCC").ToString();
            NhapKho_PB.NguoiGiaoHang = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGUOIGIAOHANG").ToString();
            NhapKho_PB.DienGiai= gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DIENGIAI").ToString();
            NhapKho_PB.NgayHachToan = Convert.ToDateTime(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAYHACHTOAN").ToString());
            NhapKho_PB.NgayChungTu = Convert.ToDateTime(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAYCHUNGTU").ToString());
            //NhapKho_PB.SoChungTu = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "SOCHUNGTU").ToString();
            //if(gridView2.DataRowCount>0)
            //    NhapKho_PB.ID = gridView2.GetRowCellValue(gridView1.FocusedRowHandle, "ID").ToString();

            
            //if (NhapKho_PB.DongYXoa == 1)
            //{
            //        for (int i = gridView2.RowCount - 1; i >= 0; i--)
            //        {
            //            DataRowView row = gridView2.GetFocusedRow() as DataRowView;
            //            if (row == null) return;

            //            NhapKho_PB.SLTon1 = Int32.Parse((row["SOLUONG"].ToString()));
            //            NhapKho_PB.MaHang = row["MAHANG"].ToString();

            //            int sl = nk_bus.LaySLTonKho(NhapKho_PB.MaHang);
            //            sl -= Int32.Parse(NhapKho_PB.SLTon1.ToString());
            //            NhapKho_PB.SoLuong = sl.ToString();
            //            nk_bus.SuaTonKho(nk_pn);
            //        }
                    
            //}
            //if (gridView2.DataRowCount > 0)
            //{
            //    for (int i = gridView2.RowCount - 1; i >= 0; i--)
            //    {
            //        DataRowView row = gridView2.GetFocusedRow() as DataRowView;
            //        if (row == null) return;

            //        NhapKho_PB.SLTon1 += Int32.Parse((row["SOLUONG"].ToString());
            //        NhapKho_PB.MaHang = row["MAHANG"].ToString();
            //    }
            //}


        }

        private void gridChiTietNhap_Click(object sender, EventArgs e)
        {

        }

        private void gridView2_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            
        }
    }
}